package com.globallogic.learning.kozius.entity;

import java.util.ArrayList;
import java.util.List;

/**
 * Class contains information about lesson entity;
 * the class is used in the curriculum entity;
 * <p/>
 * Created by sergii.koziumynskyi on 2/4/14.
 */
public final class Lesson {
    public Lesson(String name, List<Integer> durationPerSemester, Examination examination) {
        this.name = name;
        this.durationPerSemester = durationPerSemester;
        this.examination = examination;
    }

    public Lesson(String name, Examination examination) {
        this.name = name;
        this.examination = examination;
    }

    public Lesson(String name) {
        this.name = name;
    }

    public Lesson() {
    }

    public int getId() {
        return id;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;

        Lesson lesson = (Lesson) o;

        if (id != lesson.id) return false;
        if (durationPerSemester != null ? !durationPerSemester.equals(lesson.durationPerSemester) : lesson.durationPerSemester != null)
            return false;
        if (examination != null ? !examination.equals(lesson.examination) : lesson.examination != null) return false;
        if (name != null ? !name.equals(lesson.name) : lesson.name != null) return false;

        return true;
    }

    @Override
    public int hashCode() {
        int result = name != null ? name.hashCode() : 0;
        result = 31 * result + (durationPerSemester != null ? durationPerSemester.hashCode() : 0);
        result = 31 * result + (examination != null ? examination.hashCode() : 0);
        result = 31 * result + id;
        return result;
    }

    @Override
    public String toString() {
        return "Lesson{" +
                "name='" + name + '\'' +
                ", durationPerSemester=" + durationPerSemester +
                ", examination=" + examination +
                ", id=" + id +
                '}';
    }

    private String name = "";
    private List<Integer> durationPerSemester = new ArrayList<Integer>();
    private Examination examination;
    private int id;
    private static int nextId = 600000000; // 6 prefix will show that it is a lesson

    {
        id = nextId;
        nextId++;
    }
}
